export default{
	//开启命名空间
	namespaced: true,
	//数据
	state:()=>({
		address:JSON.parse(uni.getStorageSync('address')||'{}'),
		token:uni.getStorageSync('token')||'',
		userinfo:JSON.parse(uni.getStorageSync('userinfo')||'{}'),
		//跳转方式和原来页面(openType,from)
		redirectInfo:null
	}),
	//方法
	mutations:{
		//address为接收的数据
		updateAddress(state,address){
			state.address=address
			//this.commit调用m_user模块下的方法
			this.commit('m_user/saveToStroage')
		},
		saveToStroage(state){
			uni.setStorageSync('address',JSON.stringify(state.address))
		},
		//更新用户
		updateUserInfo(state,userinfo){
			state.userinfo=userinfo
			this.commit('m_user/saveUserInfo')
		},
		saveUserInfo(state){
			uni.setStorageSync('userinfo',JSON.stringify(state.userinfo))
		},
		updateToken(state,token){
			if(token==="clear")
			state.token=''
			else 
			state.token="Bearer eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJ1aWQiOjIzLCJpYXQiOjE1NjQ3MzAwNzksImV4cCI6MTAwMTU2NDczMDA3OH0.YPt-XeLnjV-_1ITaXGY2FhxmCe4NvXuRnRB8OMCfnPo"
			this.commit('m_user/saveToken')
		},
		saveToken(state){
			uni.setStorageSync('token',JSON.stringify(state.token))
		},
		updateRedirectInfo(state,info){
			state.redirectInfo=info
		}
	},
	//数据包装器
	getters:{
		addstr(state){
			if(!state.address.provinceName) return ''
			return state.address.provinceName+state.address.cityName+state.address.countyName+state.address.detailInfo
		}
	}
}